$(document).ready(function() {
    var tabUserLoaded = $.Storage.loadItem('userPageTabs');


    $('.user-painel .nav-tabs').on('click.storageUser', 'a', function() {

        $.Storage.saveItem('userPageTabs', $(this).attr('href'));

    });


    if (tabUserLoaded != false) {
        $('a[href="' + tabUserLoaded + '"]').trigger('click');
    }


    $('a[role="detailsUserLeilao"]').on('click', function(e) {
        e.preventDefault();
        var id = $(this).attr('data-id');

        $('.lote-header.line-' + id).slideToggle({duration: 400,
            done: function(prom, idn) {

            }});

    });
    
    $('[data-trigger-fancybox]').click(function(e) {
        e.preventDefault();

        var $url = $(this).attr('data-url'),
            $type = $(this).attr('data-type') ? $(this).attr('data-type')  : 'ajax',
            $id  = $(this).attr('data-id') ? '/'.$(this).attr('data-id') : '';
            
           
           $url = $url + $id;
        $.fancybox({
            href: $url,
            type: $type,
            padding: 5
          
        });
    });
    
    $('[click-send-comprovante]').click(function(e) {
        e.preventDefault();

        var $url = $(this).attr('data-url');
        $.fancybox({
            href: $url,
            type: 'ajax',
            padding: 5,
            width: 250,
            height: 170,
            scrolling: 'no',
            autoResize: false,
            autoSize: false,
            afterShow : function() {
                
                $('.css3button').on('click',function(){
                    var $input = $(this).attr('data-trigger');
                    $($input).trigger('click').change(function(){
                        
                           var $files = this.files,
                               $ifile  = $files['0'],
                               $mimes = ['jpg','gif','png','JPG','PNG','GIF'],
                               $name  =  $ifile.name,
                               $extension = '';
                               pattern = /[\.]/gi;
                                
                               if(pattern.test($name)){
                                      var $array = $name.split(pattern);
                                          $array = $array.reverse();
                                          $extension = $array['0'];
                                          if(in_array($extension,$mimes)){
                                              $('.info-image').text($name);
                                               return;
                                          }
                               }
                               this.value = '';
                               alert('Tipo de arquivo não aceito');
                               
                               
                           
                           
                        
                    });
                    
                    
                 });
            }
        });
    });

});